package com.df.ez_game.server.logic;

import com.baidu.bjf.remoting.protobuf.Codec;
import com.baidu.bjf.remoting.protobuf.ProtobufProxy;
import com.df.ez_game.server.IEzGameMsgCodec;
import com.df.ez_game.server.msg.client.ClientReqMsg;
import com.df.ez_game.server.msg.client.ClientRespMsg;
import com.df.ez_game.tools.EzConstant;

import java.io.IOException;

public class ProtobufCodec implements IEzGameMsgCodec {
    @Override
    public byte[] encodeNetMsg(ClientRespMsg resp) {
        Codec<ClientRespMsg> codec = ProtobufProxy.create(ClientRespMsg.class);
        try {
            byte[] bytes = codec.encode(resp);
            return bytes;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return EzConstant.ProtoConstant.emptyBytes;
    }

    @Override
    public ClientReqMsg decodeNetMsg(byte[] reqBytes) {
        Codec<ClientReqMsg> codec = ProtobufProxy.create(ClientReqMsg.class);
        try {
            ClientReqMsg msg = codec.decode(reqBytes);
            return msg;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public byte[] encodeBusinessMsg(Object resp,Class clazz) {
        return new byte[0];
    }

    @Override
    public Object decodeBusinessMsg(byte[] reqBytes,Class clazz) {
        return null;
    }
}
